package com.elinkway.infinitemovies.async;

import android.content.Context;
import android.os.Bundle;

import com.elinkway.infinitemovies.bean.CloudDiskBean;
import com.elinkway.infinitemovies.http.api.MoviesHttpApi;
import com.elinkway.infinitemovies.http.api.MoviesHttpApi.LeTvBitStreamParam;
import com.elinkway.infinitemovies.http.parser.CloudDiskParser;
import com.elinkway.infinitemovies.utils.LogUtils;
import com.elinkway.infinitemovies.utils.MoviesConstant;
import com.lvideo.http.bean.LVideoDataHull;

public class RequestCloudDiskTask extends MoviesHttpAsyncTask <CloudDiskBean>{

	private String mCode;
	
	private String mType;
	
	public  String mCdeype;
	
	private RequestStreamResultListener<CloudDiskBean> mListener;

	private String currClarity = "";

	public String getCurrClarity() {
		return currClarity;
	}

	public void setCurrClarity(String currClarity) {
		this.currClarity = currClarity;
	}

	public RequestCloudDiskTask(Context context) {
		super(context);
	}

	public void setmListener(RequestStreamResultListener<CloudDiskBean> mListener) {
		this.mListener = mListener;
	}
	
	public void setParameter(String code, String type) {
		mCode = code;
		mType = type;
	} 

	@Override
    public LVideoDataHull<CloudDiskBean> doInBackground() {
        Bundle params = new Bundle();
        params.putString(LeTvBitStreamParam.KEY_CLOUD_CODE, mCode);
        params.putString(LeTvBitStreamParam.KEY_TYPE, mType);
        params.putString(LeTvBitStreamParam.KEY_SRC, "nets");
        params.putString(MoviesHttpApi.LeTvBitStreamParam.KEY_REQUESTTYPE,
                LeTvBitStreamParam.KEY_PLAY);
        params.putString(LeTvBitStreamParam.KEY_CDETYPE, LeTvBitStreamParam.KEY_CDETYPE_AES);
        return MoviesHttpApi.requestLVideoStream(new CloudDiskParser(currClarity), params);
    }

	@Override
	public void onPostExecute(int updateId, CloudDiskBean result) {
		if(null != mListener){
			mListener.onRequestSuccess(updateId, result);
		}
	}

	@Override
	public void netNull() {
		super.netNull();
		if(null != mListener){
			LogUtils.e("PlayMediaController", "request cloud data netNull and reason is net is unavailable");
			mListener.onRequestFailed();
		}
	}

	@Override
	public void netErr(int updateId, String errMsg) {
		super.netErr(updateId, errMsg);
		if(null != mListener){
			LogUtils.e("PlayMediaController", "request cloud data netErr and reason is request exception");
			mListener.onRequestFailed();
		}
	}

	@Override
	public void dataNull(int updateId, String errMsg) {
		super.dataNull(updateId, errMsg);
		if(null != mListener){
			mListener.onRequestFailed(MoviesConstant.RESPONSE_DATA_ERROR, errMsg);
			LogUtils.e("PlayMediaController", "request cloud data dataNull and reason is data is null");
		}
	}

	@Override
	public void codeErr(String code, String msg) {
		mListener.onRequestFailed(code, msg);
		super.codeErr(code, msg);
	}
	
}

